﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Entities;

namespace Presentation
{
    public partial class InputCardNo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session.Clear();
            }
        }

        protected void btn1_Click(object sender, EventArgs e)
        {
            txtCardNo.Text += "1";
        }

        protected void btn2_Click(object sender, EventArgs e)
        {
            txtCardNo.Text += "2";
        }

        protected void btn3_Click(object sender, EventArgs e)
        {
            txtCardNo.Text += "3";
        }

        protected void btn4_Click(object sender, EventArgs e)
        {
            txtCardNo.Text += "4";
        }

        protected void btn5_Click(object sender, EventArgs e)
        {
            txtCardNo.Text += "5";
        }

        protected void btn6_Click(object sender, EventArgs e)
        {
            txtCardNo.Text += "6";
        }

        protected void btn7_Click(object sender, EventArgs e)
        {
            txtCardNo.Text += "7";
        }

        protected void btn8_Click(object sender, EventArgs e)
        {
            txtCardNo.Text += "8";
        }

        protected void btn9_Click(object sender, EventArgs e)
        {
            txtCardNo.Text += "9";
        }

        protected void btn0_Click(object sender, EventArgs e)
        {
            txtCardNo.Text += "0";
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtCardNo.Text = "";
        }

        protected void btnEnter_Click(object sender, EventArgs e)
        {
            CardReaderBLL cDB = new CardReaderBLL();
            CardsEntity cE = new CardsEntity();
            CardBLL cB = new CardBLL();
            cE.CardNo = txtCardNo.Text;
            if (cDB.AcceptCard(cE) == true && cB.GetAttempt(cE) < 3)
            {
                //Add session CardNo
                Session.Add("CardNo", txtCardNo.Text);                
                Response.Redirect("Screen.aspx?id=1");
            }
            else
            {
                Response.Redirect("Screen.aspx?id=2");
            }
        }
    }
}